/**
 * 单例问题
 */
public class Single {//单例模式 饿汉模式
    private static Single single=new Single();
    private Single(){}
    public static Single getInstance(){
        return single;
    }
    static class Single1{//单例模式 懒汉模式
        private static Single1 single1;
        private Single1(){}
        public static Single1 getInstance(){
            if(single1==null){//双重检测 效率高
               synchronized (Single1.class){//同步方法
                   if(single1==null){
                       single1=new Single1();
                   }
               }
            }
            return single1;
        }
    }
    static class SingleInstance{//通静态内部类的方法做到懒加载并且线程安全
        private static final Single INSTANCE=new Single();
    }
    public static Single getInnerInstance(){
        return SingleInstance.INSTANCE;
    }
    public enum SingleEnum{
        mon,
        eve,
        hello,
        未知错误;
//        int index;
//        String name;
//        SingleEnum(int index, String name) {
//            this.index = index;
//            this.name = name;
//        }
    }
    public static void main(String[] args) {
        System.out.println(Single1.getInstance());
        System.out.println(Single1.getInstance());
        System.out.println(Single1.getInstance());
        System.out.println(getInnerInstance());
        System.out.println(getInnerInstance());
        System.out.println(getInnerInstance());
    }
}
